package com.tszs.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tszs.biz.FinancialDetailsBiz;
import com.tszs.entity.FinancialDetails;
import com.tszs.entity.FinancialDetailsExample;
import com.tszs.util.CallBack;
import com.tszs.util.Uuid;

import net.sf.json.JSONObject;
/**
 * @类名:FinancialDetailsController
 * @类描述：商家账号明细
 * @创建时间：2019-03-22 13:07:07
 * @创建人：王俊
 * @author Administrator
 *
 */
@Controller
public class FinancialDetailsController {
	/**
	 * @FinancialDetailsBiz
	 * @描述:商家账号明细
	 * @创建时间:201903-21 13:14:14
	 */
	@Autowired
	private FinancialDetailsBiz financialDetailsBiz;
	/**
	 * @方法名:FinancialDetailsListPage
	 * @方法描述：商家账号明细
	 * @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/FinancialDetailsListPage")
	public void findCommodityListPage(HttpServletRequest request,HttpServletResponse response) {
		response.setContentType("text/xml; charset=UTF-8");
		response.setContentType("text/html;charset=utf-8");
		int page = Integer.parseInt(request.getParameter("page"));
		int limit = Integer.parseInt(request.getParameter("limit"));
		String begin=request.getParameter("type3");
		String type=request.getParameter("type");
		String end=request.getParameter("type4");
		FinancialDetails example = new FinancialDetails();
		example.setPage((page - 1) * limit);
		example.setLimit(limit);
		if (!(null == begin) && !(null == end)) {
			if (!"".equals(begin) && !"".equals(end)) {
				begin = begin + " 00:00:01";
				end = end + " 23:59:59";
				example.setBegin(begin);
				example.setEnd(end);
			}
		}
		List<FinancialDetails> selectByExample = financialDetailsBiz.selectByExamplePage(example);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", selectByExample.size());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < selectByExample.size(); i++) {
			Map<String, Object> mapData = new HashMap<String, Object>();
			mapData.put("Id", i+1);
			mapData.put("UsersId", selectByExample.get(i).getUsersId());
			mapData.put("UsersName", selectByExample.get(i).getUsersName());
			mapData.put("AmountOfMoney", selectByExample.get(i).getAmountOfMoney());
			mapData.put("fCreateTime", selectByExample.get(i).getfCreateTime());
			mapData.put("pId", selectByExample.get(i).getpId());
			mapData.put("cId", selectByExample.get(i).getpId());
			mapData.put("button","<a href=\"javascript:table('1','"
							+ selectByExample.get(i).getfId() + "')\" class=\"layui-btn layui-btn-xs\">删除</a>");
			if(type.equals("2")) {
				mapData.put("fType", selectByExample.get(i).getfType().equals("1")?"商品卖出":"分销出售");
				mapData.put("cId",selectByExample.get(i).getcId());
			}
			list.add(mapData);
		}
		map.put("data", list);
		JSONObject json = JSONObject.fromObject(map);
		new CallBack().textObject(json, response);
	}
	/**
	 * @方法名:FinancialDetailsDelete
	 * @方法描述：财务明细根据ID删除
	 * @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/FinancialDetailsDelete")
	public void FinancialDetailsDelete(HttpServletRequest request,HttpServletResponse response) {
		FinancialDetails record=new FinancialDetails();
		record.setfStatic("1");
		FinancialDetailsExample example=new FinancialDetailsExample();
		com.tszs.entity.FinancialDetailsExample.Criteria ca=example.createCriteria();
		ca.andFIdEqualTo(request.getParameter("id"));
		int i=financialDetailsBiz.updateByExampleSelective(record, example);
		if(i>0) {
			new CallBack().yes(response, "", "");
		}else {
			new CallBack().no(response, "", "");
		}
	}
	public static void main(String[] args) {
		System.out.println(Uuid.getUUID());
	}
}
